package com.td.client.gui;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Vector2f;

import com.td.core.obj.TDMap;
import com.td.core.obj.unit.Unit;

public class UnitRenderer implements TDMap.DrawParams {
	
	private static UnitRenderer unitRenderer;
	
	TDAnimation animation;
	
	private UnitRenderer() {
		Image spider = null;
		try {
			spider = new Image("data/images/spider.png");
		} catch (SlickException e) {
			e.printStackTrace();
		}
		animation = new TDAnimation(spider, 30, 20);
	}
	
	public static UnitRenderer getInstance() {
		if(unitRenderer == null)
			unitRenderer = new UnitRenderer();
		return unitRenderer;
	}
	
	public void draw(int sx, Unit u, Graphics g) {
		
		float ux = sx + u.getRealPosition().getX();
		float uy = u.getRealPosition().getY();
		float us = u.getSize();

		if(ux + us > sx  && ux < sx + TDMap.Screen.X) {
			g.setColor(Color.white);
			
			animation.setDirection(new Vector2f(u.getRotation()));
			animation.update();
			animation.draw(ux, uy);
		}
	}
}
